package Analysis;

import java.awt.List;

import Data.CarDataModel;
import SystemControl.SystemManager;
import UserInterface.UI;

public class ComputeRisk extends SystemManager {
	private static final int SAFETY_VALUE = 10;
	public ComputeRisk() {
	}
	
	// compute distance
	public static int compute_data(CarDataModel currentCar, CarDataModel frontCar, int rate) {
		double minDistance;
		int result = 0;
		
		minDistance = (0.5 * currentCar.velocity) + 0.01 * (Math.pow(currentCar.velocity, 2) - Math.pow(frontCar.velocity, 2) ) ;
		minDistance *= (double)rate * 0.01;
		minDistance += SAFETY_VALUE;
//		System.out.println(""+rate);
		UI.label_min_distance.setText(""+minDistance);
		
		if(currentCar.distanceToFront * 0.4 > minDistance)
			result = 1; //Normal
		else if(currentCar.distanceToFront * 0.6 > minDistance)
			result = 2; // care
		else if(currentCar.distanceToFront * 0.9 > minDistance)
			result = 3; // wanning
		else
			result = 4;// danger
		
		return result;
	}
	
}
